import requests

from api.open_account_api import OpenAccountApi
from api.reg_login_api import RegLoginApi
from common.util import common_assert, html_util


class TestOpenAccount:

    def setup(self):
        # 创建session对象
        self.ses = requests.session()
        # 实例化封装接口请求的类
        self.reg_login_api = RegLoginApi(self.ses)
        self.open_account = OpenAccountApi(self.ses)

    # 实名认证测试用例
    def test01_realname(self):
        # 实现登录接口
        self.reg_login_api.user_login("18743264321", "qqq123")
        # 实现实名认证接口
        resp = self.open_account.realname("张三", "450102199003078798")
        # 断言
        common_assert(resp, 200, "成功")
        resp_dcit = resp.json()
        assert "450****798" == resp_dcit.get("data").get("card_id")
        assert "张**" == resp_dcit.get("data").get("realname")

    # 开户测试用例
    def test02_open_account(self):
        # 实现登录接口
        self.reg_login_api.user_login("18743264321", "qqq123")
        # 实现开户接口
        resp = self.open_account.open_account()
        # 断言
        common_assert(resp, 200, "form")

    # 第三方开户测试用例
    def test03_third_open_account(self):
        # 实现登录接口
        self.reg_login_api.user_login("18743264321", "qqq123")
        # 实现开户接口
        resp = self.open_account.open_account()
        # 实现第三方开户接口
        data_list = html_util(resp)  # 调用第三方html解析工具方法
        resp1 = self.open_account.third_open_account(data_list[0], data_list[1])
        # 断言
        assert 200 == resp1.status_code
        assert "OK" in resp1.text
